﻿jQuery(window).load(function() {
    //loadCountPendingRequest();
    //initAutoNotification();
    //loadNewBookNotifi(false);
});
// load pending count
function loadCountPendingRequest() {
    $.ajax({
        method: "GET",
        url: "/HolidayManagement/CountPendingRequest",
        success: function (data) {
            if (data > 0) {
                $('#Menu_PendingRequestNum').html(data);
                $('#Menu_PendingRequestNum').show();
            } else {
                $('#Menu_PendingRequestNum').hide();
            }
        },
        error: function () {
            $('#Menu_PendingRequestNum').hide();
        }
    });
};
// load pending count
function initAutoNotification() {
    loadCountBookNotiUnread();
     var auto_refresh = setInterval(
        function () {
            loadCountBookNotiUnread();
        }, 10000); // refresh every 10000 millisecon

    }
   
function loadCountBookNotiUnread() {
    $.ajax({
        method: "GET",
        url: "/Notification/CountUnreadBookNotification",
        data: { personalId: $('#ajaxcurrentpersonalid').val() },
        success: function (data) {
        
            if (data > 0) {
                if (data>$('#Menu_CountUnreadBookNotification').text() ) {
                    $('#header_notification_bar').pulsate({
                        color: "#fcb322",
                            repeat: false
                        });
                    }
                $('#Menu_CountUnreadBookNotification').html(data);
                $('#Menu_CountUnreadBookNotification').show();
                
            } else {
                $('#Menu_CountUnreadBookNotification').html('0');
                $('#Menu_CountUnreadBookNotification').hide();
            }

        },
        error: function () {
            $('#Menu_CountUnreadBookNotification').hide();
        }
    });
};

function loadBookNotifi() {
    var countNew = $('#Menu_CountUnreadBookNotification').text();
    //if (countNew > 0) {
        loadNewBookNotifi(true);
    //}
}
function loadNewBookNotifi(markRead)
{
    $("#listNewBookNotification").html("<div class='ajax-loading'></div>");
    $.ajax({
        method: "GET",
        url: "/Notification/NewBookNotification",
        data: { personalId: $('#ajaxcurrentpersonalid').val(), markRead: markRead },
        success: function (data) {
            $("#listNewBookNotification").html(data);
            $("#listbooknotificontent").slimScroll({
                size: '7px',
                color: '#a1b2bd',
                railColor: '#333',
                height: 250,
                alwaysVisible: false,
                railVisible: false,
                disableFadeOut: true
            });

        },
        error: function () {
            $("#listNewBookNotification").html("load failed");
        }
    });
}